package com.ctbri.io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

class S1 implements Serializable{
	private String name = "s1";

	@Override
	public String toString() {
		return "S1 [name=" + name + "]";
	}
}

class S2 implements Serializable {
	private String name = "s2";
	private S1 s1 = new S1();
	@Override
	public String toString() {
		return "S2 [name=" + name + ", s1=" + s1 + "]";
	}
	
}

public class Ex27 {

	public static void main(String[] args) throws IOException, ClassNotFoundException {
		S2 s2 = new S2();
		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("ex27.out"));
		out.writeObject(s2);
		
		ObjectInputStream in = new ObjectInputStream(new FileInputStream("ex27.out"));
		S2 tmp = (S2)in.readObject();
		System.out.println(tmp);
	}

}
